<?php

Class Shop{

    static $ingridients = array();
    static $elixirs = array();
    static $clothing = array();
    static $artifact = array();
    static $boiler = array();
    static $mortar = array();
    static $pet = array();
    static $podkova = array();
    static $seed = array();
    static $food = array();
    static $skin = array();
    
    
    static function getOne($id, $good ){
        
        switch($good){
            case "skin":
            #return "mortar";
            if(isset(Shop::$skin[$id])) return Shop::$skin[$id];
            Goods::getAll();
            return Goods::$all["skin"][$id];
            break;
            
            case "podkova":
            #return "mortar";
            if(isset(Shop::$podkova[$id])) return Shop::$podkova[$id];
            Goods::getAll();
            return Goods::$all["podkova"][$id];
            break;
            
            case "mortar":
            #return "mortar";
            if(isset(Shop::$mortar[$id])) return Shop::$mortar[$id];
            Goods::getAll();
            return Goods::$all["mortar"][$id];
            break;
            
            case "artifact":
            #return "mortar";
            if(isset(Shop::$artifact[$id])) return Shop::$artifact[$id];
            Goods::getAll();
            return Goods::$all["artifact"][$id];
            break;
            
            case "boiler":
            #return "mortar";
            if(isset(Shop::$boiler[$id])) return Shop::$boiler[$id];
            Goods::getAll();
            return Goods::$all["boiler"][$id];
            break;
            
            case "clothing":
            #return "mortar";
            if(isset(Shop::$clothing[$id])) return Shop::$clothing[$id];
            Goods::getAll();
            return Goods::$all["clothing"][$id];
            break;
            
            case "potion":
            #return "potion";
            if(isset(Shop::$elixirs[$id])) return Shop::$elixirs[$id];
            return Book::getGreen($id);
            #return Book::$greens;//[$id];
            break;
            
            case "ingredient":
            #return "mortar";
            if(isset(Shop::$ingridients[$id])) return Shop::$ingridients[$id];
            Habars::getElement($id);
            return Habars::$elements[$id];
            break;
            
            case "pet":
            #return "mortar";
            if(isset(Shop::$pet[$id])) return Shop::$pet[$id];
            Pet::getPets($id);
            return Pet::$pets[$id];
            break;
            
            case "seed":
            #return "mortar";
            if(isset(Shop::$seed[$id])) return Shop::$seed[$id];
            if( !$seed = Seed::getOne($id) ){
                Connect::_error("Нет такой семачки");
                return false;
            }
            return $seed;
            break;
            
            case "food":
            #return "mortar";
            if(isset(Shop::$food[$id])) return Shop::$food[$id];
            Goods::getAll();
            #Food::getAll();
            if( !isset(Goods::$all["food"][$id]) ){
            #if( !isset(Food::$all[$id]) ){
                Connect::_error("Нет такой еды");
                return false;
            }
            #return Food::$all[$id];
            return Goods::$all["food"][$id];
            break;
        }                
         
    }
    
    
    /**
     * все
    */
    static function getAll($index = false){
        Habars::getHabars();
        Book::getBook();
        Goods::getAll();        
        Pet::getPets();        
        Seed::getAll();
        #Food::getAll();
        
        $ingr = array();
        $elixirs = array();
        
        if(count(Shop::$ingridients) == 0) foreach(Habars::$habars as $key => $val){
            foreach($val['elements'] as $keyEl => $valKey){
                if($index != true){
                    Shop::$ingridients[$keyEl] = $valKey;
                }else{
                    Shop::$ingridients[] = $valKey;    
                }
            }
        }
        
        if(count(Shop::$elixirs) == 0) foreach(Book::$book as $key => $val){
            foreach($val['green'] as $keyGr => $valGr){
                unset($valGr['recept']);
                if($index != true){
                    Shop::$elixirs[$keyGr] = $valGr;
                }else{
                    Shop::$elixirs[] = $valGr;   
                }
            }
        }
        
        if(count(Shop::$clothing) == 0) foreach(Goods::$all["clothing"] as $key => $val){
                         
                if($index != true){
                    Shop::$clothing[$key] = $val;
                }else{
                    Shop::$clothing[] = $val;   
                }
        }
        
        if(count(Shop::$artifact) == 0) foreach(Goods::$all["artifact"] as $key => $val){
                        
                if($index != true){
                    Shop::$artifact[$key] = $val;
                }else{
                    Shop::$artifact[] = $val;   
                }
        }
        
        if(count(Shop::$boiler) == 0) foreach(Goods::$all["boiler"] as $key => $val){ 
                if($index != true){
                    Shop::$boiler[$key] = $val;
                }else{
                    Shop::$boiler[] = $val;   
                }
        }
        
        if(count(Shop::$podkova) == 0) foreach(Goods::$all["podkova"] as $key => $val){ 
                if($index != true){
                    Shop::$podkova[$key] = $val;
                }else{
                    Shop::$podkova[] = $val;   
                }
        }
        
        if(count(Shop::$mortar) == 0) foreach(Goods::$all["mortar"] as $key => $val){
                           
                if($index != true){
                    Shop::$mortar[$key] = $val;
                }else{
                    Shop::$mortar[] = $val;   
                }
        }
        
        if(count(Shop::$skin) == 0) foreach(Goods::$all["skin"] as $key => $val){
                           
                if($index != true){
                    Shop::$skin[$key] = $val;
                }else{
                    Shop::$skin[] = $val;   
                }
        }
        
        if(count(Shop::$pet) == 0) foreach(Pet::$pets as $key => $val){
            
                unset($valGr['skins']);
                if($index != true){
                    Shop::$pet[$key] = $val;
                }else{
                    Shop::$pet[] = $val;   
                }
        }
        
        if(count(Shop::$seed) == 0) {
            if($index != true){
                    Shop::$seed = Seed::$all;
            }else{
                    Shop::$seed = array_values( Seed::$all );
            }    
        }
        
        if(count(Shop::$food) == 0) {
                           
                if($index != true){
                    Shop::$food = Goods::$all["food"];
                }else{
                    Shop::$food = array_values( Goods::$all["food"] );  
                }
        }

        return true;
    }    
}
?>